﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Project.Teller
{
    public partial class UpdateTeller : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataPOFDataContext db = new DataPOFDataContext();
            string acc = (from x in db.AccountLogins where x.Username == Session["username"].ToString() select x.FullName).FirstOrDefault();
            Label1.Text = acc;
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Session["username"] = null;
            Response.Cache.SetNoStore();
            Response.CacheControl = "no-cache";
            Response.Redirect("../Home/Login.aspx");
        }
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataPOFDataContext db = new DataPOFDataContext();
            string route = DropDownList1.SelectedItem.ToString() + DropDownList2.SelectedItem.ToString();
            int routid = (from x in db.Routes where x.Route1 == route select x.ID).FirstOrDefault();

            int Distance = (from x in db.RouteDetails where x.ID == routid select x.Distance).FirstOrDefault();
            Label6.Text = Distance.ToString();
            decimal DistancePrice = (from x in db.PriceOfVolumes where x.ID == 1 select x.Distance).FirstOrDefault();
            int a = Convert.ToInt32(DistancePrice) * Distance;

            if (Label6.Text == "0")
            {
                Label2.Text = "Free";
                double b = Convert.ToDouble(Label3.Text);
                double c = Convert.ToDouble(Label4.Text);
                Label5.Text = Convert.ToString(c + b);
            }
            else
            {
                Label2.Text = a.ToString();
                double b = Convert.ToDouble(Label3.Text);
                double c = Convert.ToDouble(Label4.Text);
                Label5.Text = Convert.ToString(a + b + c);
            }
        }

        protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataPOFDataContext db = new DataPOFDataContext();
            string route = DropDownList1.SelectedItem.ToString() + DropDownList2.SelectedItem.ToString();
            int routid = (from x in db.Routes where x.Route1 == route select x.ID).FirstOrDefault();
            int Distance = (from x in db.RouteDetails where x.ID == routid select x.Distance).FirstOrDefault();

            Label6.Text = Distance.ToString();
            decimal DistancePrice = (from x in db.PriceOfVolumes where x.ID == 1 select x.Distance).FirstOrDefault();
            int a = Convert.ToInt32(DistancePrice) * Distance;
            if (Label6.Text == "0")
            {
                Label2.Text = "Free";
                double b = Convert.ToDouble(Label3.Text);
                double c = Convert.ToDouble(Label4.Text);
                Label5.Text = Convert.ToString(c + b);
            }
            else
            {
                Label2.Text = a.ToString();
                double b = Convert.ToDouble(Label3.Text);
                double c = Convert.ToDouble(Label4.Text);
                Label5.Text = Convert.ToString(a + b + c);
            }
        }

        protected void TextBox1_TextChanged(object sender, EventArgs e)
        {
            DataPOFDataContext db = new DataPOFDataContext();
            decimal Distance = (from x in db.PriceOfVolumes select x.Volume).FirstOrDefault();
            decimal z = 0;

            if (Convert.ToDouble(TextBox1.Text) < 1)
            {
                z = Convert.ToDecimal(TextBox1.Text) * Distance;
                Label3.Text = z.ToString();
                double a = Convert.ToDouble(Label2.Text);
                double c = Convert.ToDouble(Label4.Text);
                Label5.Text = Convert.ToString(a + 1000 + c);
            }
            else
            {
                z = Convert.ToDecimal(TextBox1.Text) * Distance;
                Label3.Text = z.ToString();
                double a = Convert.ToDouble(Label2.Text);
                double c = Convert.ToDouble(Label4.Text);
                Label5.Text = Convert.ToString(a + c + Convert.ToDouble(z));
            }
        }

        protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataPOFDataContext db = new DataPOFDataContext();
            string z = DropDownList3.SelectedValue.ToString();
            decimal ServicePrice = (from x in db.Services where x.Service1 == z select x.Price).FirstOrDefault();
            Label4.Text = Convert.ToString(ServicePrice);
            double a = Convert.ToDouble(Label2.Text);
            double b = Convert.ToDouble(Label3.Text);
            double c = Convert.ToDouble(ServicePrice);
            Label5.Text = Convert.ToString(a + b + c);
        }
    }
}